﻿using System;
using System.Collections.Generic;
using System.Text;
using AspNetCs.IDAL;
using System.Data;
using AspNetCs.Config;
using AspNetCs.Model;
using AspNetCs.Common;
namespace AspNetCs.SQLServerDAL
{
    public class Memorial_Type_DAL : IMemorial_Type
    {
        #region IMemorial 成员

        public DataTable GetDataTable(string filter)
        {
            DataTable dt = new DataTable();
            db Conn = new db();
            try
            {
                dt = Conn.GetSql_DataTable("Select * from memorial_Type Where ID<>0 " + filter);
            }
            catch (Exception ex)
            {
                new CustomException(ex);
            }
            finally
            {
                Conn.close();
            }
            return dt;
        }


        public int Update(Memorial_Type_Model model)
        {
            int result = 0;
            db Conn = new db();
            db.ParameterArry[] par = new db.ParameterArry[5];
            par[0].dbType = SqlDbType.Int;
            par[0].objValue = model.Id;
            par[0].parName = "@Id";

            par[1].dbType = SqlDbType.VarChar;
            par[1].objValue = model.TypeName;
            par[1].parName = "@TypeName";

            par[2].dbType = SqlDbType.VarChar;
            par[2].objValue = model.TypePoint;
            par[2].parName = "@TypePoint";

            par[3].dbType = SqlDbType.VarChar;
            par[3].objValue = model.Readme;
            par[3].parName = "@Readme";

            par[4].dbType = SqlDbType.Int;
            par[4].objValue = model.OrderId;
            par[4].parName = "@OrderId";

            try
            {
                result = Conn.ExcSql("Update memorial_Type Set  OrderId=@OrderId, TypeName=@TypeName,TypePoint=@TypePoint,Readme=@Readme where id=@Id", par);
            }
            catch (Exception Ex)
            {
                new CustomException(Ex);
                result = -1;
            }
            finally
            {
                Conn.close();
            }
            return result;
        }


        public Memorial_Type_Model GetModel(DataRow dr)
        {
            Memorial_Type_Model model = new Memorial_Type_Model();
            if (dr["Id"] != null) model.Id = StringHelper.isNumber_int(dr["Id"].ToString());
            if (dr["TypeName"] != null) model.TypeName = dr["TypeName"].ToString();
            if (dr["TypePoint"] != null) model.TypePoint = dr["TypePoint"].ToString();
            if (dr["Readme"] != null) model.Readme = dr["Readme"].ToString();
            if (dr["Addtime"] != null) model.Addtime = Convert.ToDateTime(dr["Addtime"].ToString());
            if (dr["OrderId"] != null) model.OrderId = StringHelper.isNumber_int(dr["OrderId"].ToString());
            if (dr["TypeInt"] != null) model.TypeInt = StringHelper.isNumber_int(dr["TypeInt"].ToString());
            

            return model;
        }

        #endregion
    }
}
